package com.vhuomai.wechat.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.vhuomai.system.constant.UserRole;
import com.vhuomai.wechat.entity.BaseWxAccount;
import com.vhuomai.wechat.service.WxAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author harris
 */
@Api(tags = "微信公众号账号")
@RestController
@RequestMapping("/api")
@Scope(role = UserRole.MANAGER)
public class WxAccountController {
    
    @Autowired
    private WxAccountService accountService;
    
    @ApiOperation(value = "获取公众号信息")
    @GetMapping(value = "/wechat/detail", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<BaseWxAccount> detail() {
        return ServiceResult.success(accountService.findOne());
    }
    
    @ApiOperation(value = "更新公众号信息")
    @PutMapping(value = "/wechat/detail", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> updateDetail(@RequestBody BaseWxAccount account) {
        accountService.update(account);
        return ServiceResult.SUCCESS;
    }
}
